
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 04/19/2013 23:00:56
-- Generated from EDMX file: C:\Desenvolvimento\visual_studio\tfs_codeplex\peschampcontrol\ProjetosManutencao\PESWebMVC\Models\PESDataBase.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [PESWEB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_ParticipantesCampeonato_Campeonato]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ParticipantesCampeonato] DROP CONSTRAINT [FK_ParticipantesCampeonato_Campeonato];
GO
IF OBJECT_ID(N'[dbo].[FK_ParticipantesCampeonato_Usuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ParticipantesCampeonato] DROP CONSTRAINT [FK_ParticipantesCampeonato_Usuario];
GO
IF OBJECT_ID(N'[dbo].[FK_CriadorCampeonato]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CampeonatoSet] DROP CONSTRAINT [FK_CriadorCampeonato];
GO
IF OBJECT_ID(N'[dbo].[FK_MesariosCampeonato_Campeonato]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MesariosCampeonato] DROP CONSTRAINT [FK_MesariosCampeonato_Campeonato];
GO
IF OBJECT_ID(N'[dbo].[FK_MesariosCampeonato_Usuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MesariosCampeonato] DROP CONSTRAINT [FK_MesariosCampeonato_Usuario];
GO
IF OBJECT_ID(N'[dbo].[FK_PartidaJogador1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PartidaSet] DROP CONSTRAINT [FK_PartidaJogador1];
GO
IF OBJECT_ID(N'[dbo].[FK_PartidaJogador2]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PartidaSet] DROP CONSTRAINT [FK_PartidaJogador2];
GO
IF OBJECT_ID(N'[dbo].[FK_CampeonatoPartida]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PartidaSet] DROP CONSTRAINT [FK_CampeonatoPartida];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioPontuacao]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PontuacaoSet] DROP CONSTRAINT [FK_UsuarioPontuacao];
GO
IF OBJECT_ID(N'[dbo].[FK_PontuacaoCampeonato]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PontuacaoSet] DROP CONSTRAINT [FK_PontuacaoCampeonato];
GO
IF OBJECT_ID(N'[dbo].[FK_JogadorUsuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[JogadorSet] DROP CONSTRAINT [FK_JogadorUsuario];
GO
IF OBJECT_ID(N'[dbo].[FK_AcaoJogador]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AcaoSet] DROP CONSTRAINT [FK_AcaoJogador];
GO
IF OBJECT_ID(N'[dbo].[FK_AcaoPartida]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AcaoSet] DROP CONSTRAINT [FK_AcaoPartida];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[CampeonatoSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CampeonatoSet];
GO
IF OBJECT_ID(N'[dbo].[UsuarioSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UsuarioSet];
GO
IF OBJECT_ID(N'[dbo].[PartidaSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PartidaSet];
GO
IF OBJECT_ID(N'[dbo].[PontuacaoSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PontuacaoSet];
GO
IF OBJECT_ID(N'[dbo].[JogadorSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[JogadorSet];
GO
IF OBJECT_ID(N'[dbo].[AcaoSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AcaoSet];
GO
IF OBJECT_ID(N'[dbo].[ParticipantesCampeonato]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ParticipantesCampeonato];
GO
IF OBJECT_ID(N'[dbo].[MesariosCampeonato]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MesariosCampeonato];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'CampeonatoSet'
CREATE TABLE [dbo].[CampeonatoSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(max)  NOT NULL,
    [DataInicio] datetime  NOT NULL,
    [DataFim] datetime  NULL,
    [QtdeRodadas] int  NOT NULL,
    [QtdeTimesRebaixados] int  NULL,
    [QtdeTimesFinalistas] int  NULL,
    [Tipo] int  NULL,
    [Criador_Id] bigint  NOT NULL
);
GO

-- Creating table 'UsuarioSet'
CREATE TABLE [dbo].[UsuarioSet] (
    [Id] bigint IDENTITY(1,1) NOT NULL,
    [Login] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'PartidaSet'
CREATE TABLE [dbo].[PartidaSet] (
    [Id] bigint IDENTITY(1,1) NOT NULL,
    [Data] datetime  NULL,
    [Rodada] int  NOT NULL,
    [GolsJogador1] int  NULL,
    [GolsJogador2] int  NULL,
    [Iniciada] bit  NOT NULL,
    [Finalizada] bit  NOT NULL,
    [CampeonatoId] int  NOT NULL,
    [Usuario1_Id] bigint  NOT NULL,
    [Usuario2_Id] bigint  NOT NULL
);
GO

-- Creating table 'PontuacaoSet'
CREATE TABLE [dbo].[PontuacaoSet] (
    [Id] bigint IDENTITY(1,1) NOT NULL,
    [Vitorias] int  NOT NULL,
    [Empates] int  NOT NULL,
    [Derrotas] int  NOT NULL,
    [GolsPro] int  NOT NULL,
    [GolsContra] int  NOT NULL,
    [TotalPontos] int  NOT NULL,
    [UsuarioId] bigint  NOT NULL,
    [Campeonato_Id] int  NOT NULL
);
GO

-- Creating table 'JogadorSet'
CREATE TABLE [dbo].[JogadorSet] (
    [Id] bigint IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(max)  NOT NULL,
    [CartoesAmarelos] int  NOT NULL,
    [CartoesVermelhos] int  NOT NULL,
    [Gols] int  NOT NULL,
    [Suspenso] bit  NOT NULL,
    [QtdeRodadasSuspenso] int  NOT NULL,
    [Usuario_Id] bigint  NOT NULL
);
GO

-- Creating table 'AcaoSet'
CREATE TABLE [dbo].[AcaoSet] (
    [Id] bigint IDENTITY(1,1) NOT NULL,
    [Texto] nvarchar(max)  NOT NULL,
    [DataHora] datetime  NOT NULL,
    [Tipo] int  NOT NULL,
    [Jogador_Id] bigint  NOT NULL,
    [Partida_Id] bigint  NOT NULL
);
GO

-- Creating table 'ParticipantesCampeonato'
CREATE TABLE [dbo].[ParticipantesCampeonato] (
    [Campeonatos_Id] int  NOT NULL,
    [Participantes_Id] bigint  NOT NULL
);
GO

-- Creating table 'MesariosCampeonato'
CREATE TABLE [dbo].[MesariosCampeonato] (
    [MesariosCampeonato_Usuario_Id] int  NOT NULL,
    [Mesarios_Id] bigint  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'CampeonatoSet'
ALTER TABLE [dbo].[CampeonatoSet]
ADD CONSTRAINT [PK_CampeonatoSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UsuarioSet'
ALTER TABLE [dbo].[UsuarioSet]
ADD CONSTRAINT [PK_UsuarioSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'PartidaSet'
ALTER TABLE [dbo].[PartidaSet]
ADD CONSTRAINT [PK_PartidaSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'PontuacaoSet'
ALTER TABLE [dbo].[PontuacaoSet]
ADD CONSTRAINT [PK_PontuacaoSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'JogadorSet'
ALTER TABLE [dbo].[JogadorSet]
ADD CONSTRAINT [PK_JogadorSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'AcaoSet'
ALTER TABLE [dbo].[AcaoSet]
ADD CONSTRAINT [PK_AcaoSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Campeonatos_Id], [Participantes_Id] in table 'ParticipantesCampeonato'
ALTER TABLE [dbo].[ParticipantesCampeonato]
ADD CONSTRAINT [PK_ParticipantesCampeonato]
    PRIMARY KEY NONCLUSTERED ([Campeonatos_Id], [Participantes_Id] ASC);
GO

-- Creating primary key on [MesariosCampeonato_Usuario_Id], [Mesarios_Id] in table 'MesariosCampeonato'
ALTER TABLE [dbo].[MesariosCampeonato]
ADD CONSTRAINT [PK_MesariosCampeonato]
    PRIMARY KEY NONCLUSTERED ([MesariosCampeonato_Usuario_Id], [Mesarios_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Campeonatos_Id] in table 'ParticipantesCampeonato'
ALTER TABLE [dbo].[ParticipantesCampeonato]
ADD CONSTRAINT [FK_ParticipantesCampeonato_Campeonato]
    FOREIGN KEY ([Campeonatos_Id])
    REFERENCES [dbo].[CampeonatoSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Participantes_Id] in table 'ParticipantesCampeonato'
ALTER TABLE [dbo].[ParticipantesCampeonato]
ADD CONSTRAINT [FK_ParticipantesCampeonato_Usuario]
    FOREIGN KEY ([Participantes_Id])
    REFERENCES [dbo].[UsuarioSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ParticipantesCampeonato_Usuario'
CREATE INDEX [IX_FK_ParticipantesCampeonato_Usuario]
ON [dbo].[ParticipantesCampeonato]
    ([Participantes_Id]);
GO

-- Creating foreign key on [Criador_Id] in table 'CampeonatoSet'
ALTER TABLE [dbo].[CampeonatoSet]
ADD CONSTRAINT [FK_CriadorCampeonato]
    FOREIGN KEY ([Criador_Id])
    REFERENCES [dbo].[UsuarioSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CriadorCampeonato'
CREATE INDEX [IX_FK_CriadorCampeonato]
ON [dbo].[CampeonatoSet]
    ([Criador_Id]);
GO

-- Creating foreign key on [MesariosCampeonato_Usuario_Id] in table 'MesariosCampeonato'
ALTER TABLE [dbo].[MesariosCampeonato]
ADD CONSTRAINT [FK_MesariosCampeonato_Campeonato]
    FOREIGN KEY ([MesariosCampeonato_Usuario_Id])
    REFERENCES [dbo].[CampeonatoSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Mesarios_Id] in table 'MesariosCampeonato'
ALTER TABLE [dbo].[MesariosCampeonato]
ADD CONSTRAINT [FK_MesariosCampeonato_Usuario]
    FOREIGN KEY ([Mesarios_Id])
    REFERENCES [dbo].[UsuarioSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MesariosCampeonato_Usuario'
CREATE INDEX [IX_FK_MesariosCampeonato_Usuario]
ON [dbo].[MesariosCampeonato]
    ([Mesarios_Id]);
GO

-- Creating foreign key on [Usuario1_Id] in table 'PartidaSet'
ALTER TABLE [dbo].[PartidaSet]
ADD CONSTRAINT [FK_PartidaJogador1]
    FOREIGN KEY ([Usuario1_Id])
    REFERENCES [dbo].[UsuarioSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PartidaJogador1'
CREATE INDEX [IX_FK_PartidaJogador1]
ON [dbo].[PartidaSet]
    ([Usuario1_Id]);
GO

-- Creating foreign key on [Usuario2_Id] in table 'PartidaSet'
ALTER TABLE [dbo].[PartidaSet]
ADD CONSTRAINT [FK_PartidaJogador2]
    FOREIGN KEY ([Usuario2_Id])
    REFERENCES [dbo].[UsuarioSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PartidaJogador2'
CREATE INDEX [IX_FK_PartidaJogador2]
ON [dbo].[PartidaSet]
    ([Usuario2_Id]);
GO

-- Creating foreign key on [CampeonatoId] in table 'PartidaSet'
ALTER TABLE [dbo].[PartidaSet]
ADD CONSTRAINT [FK_CampeonatoPartida]
    FOREIGN KEY ([CampeonatoId])
    REFERENCES [dbo].[CampeonatoSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CampeonatoPartida'
CREATE INDEX [IX_FK_CampeonatoPartida]
ON [dbo].[PartidaSet]
    ([CampeonatoId]);
GO

-- Creating foreign key on [UsuarioId] in table 'PontuacaoSet'
ALTER TABLE [dbo].[PontuacaoSet]
ADD CONSTRAINT [FK_UsuarioPontuacao]
    FOREIGN KEY ([UsuarioId])
    REFERENCES [dbo].[UsuarioSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioPontuacao'
CREATE INDEX [IX_FK_UsuarioPontuacao]
ON [dbo].[PontuacaoSet]
    ([UsuarioId]);
GO

-- Creating foreign key on [Campeonato_Id] in table 'PontuacaoSet'
ALTER TABLE [dbo].[PontuacaoSet]
ADD CONSTRAINT [FK_PontuacaoCampeonato]
    FOREIGN KEY ([Campeonato_Id])
    REFERENCES [dbo].[CampeonatoSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PontuacaoCampeonato'
CREATE INDEX [IX_FK_PontuacaoCampeonato]
ON [dbo].[PontuacaoSet]
    ([Campeonato_Id]);
GO

-- Creating foreign key on [Usuario_Id] in table 'JogadorSet'
ALTER TABLE [dbo].[JogadorSet]
ADD CONSTRAINT [FK_JogadorUsuario]
    FOREIGN KEY ([Usuario_Id])
    REFERENCES [dbo].[UsuarioSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_JogadorUsuario'
CREATE INDEX [IX_FK_JogadorUsuario]
ON [dbo].[JogadorSet]
    ([Usuario_Id]);
GO

-- Creating foreign key on [Jogador_Id] in table 'AcaoSet'
ALTER TABLE [dbo].[AcaoSet]
ADD CONSTRAINT [FK_AcaoJogador]
    FOREIGN KEY ([Jogador_Id])
    REFERENCES [dbo].[JogadorSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AcaoJogador'
CREATE INDEX [IX_FK_AcaoJogador]
ON [dbo].[AcaoSet]
    ([Jogador_Id]);
GO

-- Creating foreign key on [Partida_Id] in table 'AcaoSet'
ALTER TABLE [dbo].[AcaoSet]
ADD CONSTRAINT [FK_AcaoPartida]
    FOREIGN KEY ([Partida_Id])
    REFERENCES [dbo].[PartidaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AcaoPartida'
CREATE INDEX [IX_FK_AcaoPartida]
ON [dbo].[AcaoSet]
    ([Partida_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------